package com.example.jdt_xiazai;

import android.widget.ArrayAdapter;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.jdt_xiazai.adapter.MainFragmentAdapter;
import com.example.jdt_xiazai.base.BaseActivity;
import com.example.jdt_xiazai.bean.FuLiBean;
import com.example.jdt_xiazai.fragment.DownloadFragment;
import com.example.jdt_xiazai.fragment.HomeFragment;
import com.example.jdt_xiazai.presenter.MainPresenter;
import com.example.jdt_xiazai.view.MainView;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity<MainPresenter> implements MainView {

    private ViewPager mPager;
    private TabLayout mTbl;

    @Override
    protected MainPresenter initPresenter() {
        return new MainPresenter();

    }

    @Override
    protected void initData() {
        basePresenter.getData();
    }

    @Override
    protected void initView() {
        mPager = findViewById(R.id.pager);
        mTbl = findViewById(R.id.tbl);


        ArrayList<Fragment> fragments = new ArrayList<>();

        fragments.add(new HomeFragment());
        fragments.add(new DownloadFragment());

        MainFragmentAdapter mainFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), fragments);


        mPager.setAdapter(mainFragmentAdapter);

        mTbl.addTab(mTbl.newTab().setText("首页"));
        mTbl.addTab(mTbl.newTab().setText("下载"));

        mTbl.setupWithViewPager(mPager);

        mTbl.getTabAt(0).setText("首页");
        mTbl.getTabAt(1).setText("下载");


    }

    @Override
    protected int getLauout() {
        return R.layout.activity_main;
    }

    @Override
    public void showData(List<FuLiBean.DataBean.DatasBean> dataBeans) {

    }
}
